package org.example.ReflectDemo.List;
class Student {
    private String name="张三";
    private int age=18;
    public Student(){
        System.out.println("Student()");
    }
    public Student(String name,int age){
        System.out.println("Student(String name,int age)");
        this.name=name;
        this.age=age;
    }
    public void eat(){
        System.out.println("Student.eat()");
    }
    private void sleep(){
        System.out.println("Student.sleep()");
    }
    public void function(String str){
        System.out.println(str);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class TestDemo {
    public static void main(String[] args) throws ClassNotFoundException {
        /*
        1.通过getClass获取Class对象
        */
        Student student=new Student();
        Class c1=student.getClass();
        /*
        2.直接通过 类名.class 的⽅式得到,该⽅法最为安全可靠，程序性能更⾼
        这说明任何⼀个类都有⼀个隐含的静态成员变量 class
        */
        Class c2=Student.class;
        //3.通过Class对象的forName()静态方法来获取
        Class c3=null;
        c3=Class.forName("org.example.ReflectDemo.List.Student");
        //⼀个类在 JVM 中只会有⼀个 Class 实例,即我们对上⾯获取的
        //c1,c2,c3进⾏ equals ⽐较，发现都是true
        System.out.println(c1.equals(c2));
        System.out.println(c1.equals(c3));
        System.out.println(c2.equals(c3));
    }
}
